#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
@Project : bigDataProject 
@File    : user_api.py
@IDE     : PyCharm 
@Author  : Mario
@Date    : 2022/11/14 10:55 
@Describe: POS用户相关接口
"""
from api.pos_api.base_pos_api import BasePosAPI
from utils.common.common_control import get_json_result
from utils.log.log_control import LogHandler

logger = LogHandler().get_logger()


class UserAPI(BasePosAPI):

    def pos_login(self):
        """
        pos端登录
        :return:
        """
        payload = '{"password":"' + self.password + '","shortNo":"' + self.short_no + '","loginMac":"' + self.login_mac + '"}'
        response = self.http_request('auth/login', payload, "pos端登录")
        return response

    def pos_work(self):
        """
        POS员工上班
        :return:
        """
        payload = '{"backCash":"0","workShiftCode":"shift' + self.brand_code + '-01"}'
        response = self.http_request('pos/work/towork', payload, "POS员工上班")
        return response

    def check_user_is_work(self) -> None:
        """检查用户是否上班状态"""
        response = self.pos_login()
        work_type = get_json_result(response, "$..towork")
        # towork:是否上班中(0：未上班/已交班，1：上班中)
        if work_type == 0:
            logger.info("当前用户上班状态为:[{}],正在进行上班操作~".format(work_type))
            self.pos_work()
